package forward.Module.Modules.Combat;

import forward.api.EventHandler;
import forward.api.Events.World.EventPacketReceive;
import forward.api.Events.World.EventPreUpdate;
import forward.api.Value.Mode;
import forward.api.Value.Numbers;
import forward.Module.Module;
import forward.Module.ModuleType;
import java.awt.Color;

import net.minecraft.network.play.server.S12PacketEntityVelocity;
import net.minecraft.network.play.server.S27PacketExplosion;

public class Velocity extends Module {
	public static Mode mode = new Mode("Mode", "mode", (Enum[]) VeloMode.values(), (Enum) VeloMode.Simple);
	private Numbers<Double> percentage = new Numbers<Double>("Percent", "Percent", 0.0, 0.0, 100.0, 5.0);

	public Velocity() {
		super("Velocity", new String[] { "antivelocity", "antiknockback", "antikb" }, ModuleType.Combat);
		this.addValues(this.percentage,mode);
		this.setColor(new Color(191, 191, 191).getRGB());
	}

	@EventHandler
	private void onPacket(EventPacketReceive e) {
		if (e.getPacket() instanceof S12PacketEntityVelocity || e.getPacket() instanceof S27PacketExplosion) {
			S12PacketEntityVelocity packet = (S12PacketEntityVelocity) e.getPacket();
			if (mode.getValue()==VeloMode.Simple){
			if (this.percentage.getValue().equals(0.0)) {
				e.setCancelled(true);
			} else {

				packet.motionX = (int) (this.percentage.getValue() / 100.0);
				packet.motionY = (int) (this.percentage.getValue() / 100.0);
				packet.motionZ = (int) (this.percentage.getValue() / 100.0);
			}
		} else if (mode.getValue()==VeloMode.MatrixSimple) {
				packet.motionX =(int) (packet.getMotionX() * 0.36);
				packet.motionZ =(int) (packet.getMotionZ() * 0.36);
				if (mc.thePlayer.onGround) {
					packet.motionX =(int) (packet.getMotionX() * 0.9);
					packet.motionZ =(int) (packet.getMotionZ() * 0.9);
				}
			}
		}
	}
	@EventHandler
	private void onUpdate(EventPreUpdate e) {
		this.setSuffix(this.mode.getValue());
	}
	enum VeloMode{
		Simple,MatrixSimple;
	}
}
